<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html;charset=utf-8"%>
<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>用户注册 - 当当网</title>
		<link href="../css/login.css" rel="stylesheet" type="text/css" />
		<link href="../css/page_bottom.css" rel="stylesheet" type="text/css" />
	</head>
	<body>
		<%@include file="../common/head1.jsp"%>
		<div class="login_step">
			注册步骤:
			<span class="red_bold">1.填写信息</span> > 2.验证邮箱 > 3.注册成功
		</div>
		<div class="fill_message">
			<form name="ctl00" method="post" action="${pageContext.request.contextPath}/user/regist.do" id="f" onsubmit="return checkForm()">
				<h2>
					以下均为必填项
				</h2>
				<table class="tab_login" >
					<tr>
						<td valign="top" class="w1">
							请填写您的Email地址：
						</td>
						<td>
							<input name="email" type="text" id="txtEmail" class="text_input" onblur="checkEmail()"/>
							<div class="text_left" id="emailValidMsg">
								<p>
									请填写有效的Email地址，在下一步中您将用此邮箱接收验证邮件。
								</p>
									<span id="emailinfo" style="color:red"></span>
								<c:if test="${param.error1 == -1}">
									<span style="color: red;">该用户已存在</span>
								</c:if>
							</div>
						</td>
					</tr>
					<tr>
						<td valign="top" class="w1">
							设置您在当当网的昵称：
						</td>
						<td>
							<input name="nickname" type="text" id="txtNickName" class="text_input"onblur="checkName()" />
							<div class="text_left" id="nickNameValidMsg">
								<p>
									您的昵称可以由小写英文字母、中文、数字组成，
								</p>
								<p>
									长度4－20个字符，一个汉字为两个字符。
								</p>
								<span id="nameinfo" style="color:red"></span>
							</div>
						</td>
					</tr>
					<tr>
						<td valign="top" class="w1">
							设置密码：
						</td>
						<td>
							<input name="password" type="password" id="txtPassword" onblur="checkPwd1()"
								class="text_input" />
							<div class="text_left" id="passwordValidMsg">
								<p>
									您的密码可以由大小写英文字母、数字组成，长度6－20位。
								</p>
								<span id="passwordinfo" style="color:red"></span>
							</div>
						</td>
					</tr>
					<tr>
						<td valign="top" class="w1">
							再次输入您设置的密码：
						</td>
						<td>
							<input name="password1" type="password" id="txtRepeatPass" onblur="checkPwd2()"
								class="text_input"/>
							<div class="text_left" id="repeatPassValidMsg">
							<span id="password1info" style="color:red"></span>
							</div>
						</td>
					</tr>
					<tr>
						<td valign="top" class="w1">
							验证码：
						</td>
						<td>
							<img class="yzm_img" id='imgVcode' src="${pageContext.request.contextPath}/user/handleVcode.do" />
							<input name="number" type="text" id="txtVerifyCode" onblur="checkVcode()"
								class="yzm_input"/>
							<div class="text_left t1">
								<p class="t1">
									<span id="vcodeValidMsg">请输入图片中的四个字母。</span>
									<c:if test="${param.error == -1}">
                                        <span style="color: red;">验证码输入错误</span>
                                    </c:if>
									<span id="numberinfo" style="color:red"></span>
									<a href="#" onclick="return changeImg()">看不清楚？换个图片</a>
								</p>
							</div>
						</td>
					</tr>
				</table>
				<div class="login_in">

					<input id="btnClientRegister" class="button_1" name="submit"  type="submit" value="注 册"/>
				</div>
			</form>
		</div>
		<%@include file="../common/foot1.jsp"%>
	<script type="text/javascript">
		function checkEmail() {
			let email = document.querySelector("#txtEmail");
			let s = document.querySelector("#emailinfo");
			let reg = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
			if(reg.test(email.value)){
				s.innerHTML = "";
				return true;
			}else{
				s.innerHTML = "邮箱格式错误";
				s.style.color = "red";
				return false;
			}
		}
		function checkName() {
			let name = document.querySelector("#txtNickName");
			let s = document.querySelector("#nameinfo");
			let reg = /([\u4E00-\u9FA5]|[a-z0-9]{2}){2,10}/;
			if(reg.test(name.value)){
				s.innerHTML = "";
				return true;
			}else{
				s.innerHTML = "昵称格式错误；"
				s.style.color = "red";
				return false;
			}
		}
		function checkPwd1() {
			let pwd1 = document.querySelector("#txtPassword");
			let s = document.querySelector("#passwordinfo");
			let reg = /\w{6,20}/;
			if(reg.test(pwd1.value)){
				s.innerHTML = "";
				return true;
			}else{
				s.innerHTML = "密码格式错误";
				s.style.color = "red";
				return false;
			}
		}
		function checkPwd2() {
			let pwd1 = document.querySelector("#txtPassword");
			let pwd2 = document.querySelector("#txtRepeatPass");
			let s = document.querySelector("#password1info");
			if(pwd2.value == pwd1.value){
				s.innerHTML = "";
				return true;
			}else{
				s.innerHTML = "两次密码不一致";
				s.style.color = "red";
				return false;
			}
		}
		function checkVcode() {
			let code = document.querySelector("#txtVerifyCode");
			let s = document.querySelector("#numberinfo");
			let reg = /\w{4}/;
			if(reg.test(code.value)){
				s.innerHTML = "";
				return true;
			}else{
				s.innerHTML = "验证码格式错误";
				s.style.color = "red";
				return false;
			}
		}

		function checkForm() {
			if(checkEmail() && checkName() && checkPwd1() && checkPwd2() && checkVcode()){
				return true;
			}
			return false;
		}

		function changeImg() {
            let code = document.querySelector("#imgVcode");
            code.src = "${pageContext.request.contextPath}/user/handleVcode.do?a="+Math.random();
            return false;
		}
	</script>
	</body>
</html>

